package com.milk.controller.user;

import com.milk.entity.Coupon;
import com.milk.result.Result;
import com.milk.service.ICouponService;
import com.milk.vo.UserCouponVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/coupon")
@ApiModel(value = "优惠卷接口")
@Slf4j
public class CouponController {
    @Autowired
    private ICouponService couponService;

    /**
     * 查询所有优惠卷信息
     * @return
     */
    @GetMapping
    @ApiModelProperty("查询所有优惠卷")
    public Result<List<UserCouponVo>> selectAll(){

        return Result.success(couponService.selectAll());
    }

    /**
     * 查询可以积分兑换的优惠卷
     * @return
     */
    @GetMapping("/integral")
    public Result<List<Coupon>> selectIntegral(){
        List<Coupon> list = couponService.selectIntegral();
        return Result.success(list);
    }

    /**
     * 积分兑换
     * @param coupon
     * @return
     */
    @PostMapping
    public Result exchange(@RequestBody Coupon coupon){
        log.info("积分兑换 = {}",coupon);
        couponService.exchange(coupon);
        return Result.success();
    }


    @PostMapping("/sdk/{sdk}")
    public Result<String > exchangeSdk(@PathVariable String sdk){
        log.info("adk兑换 = {}",sdk);
        String mgs = couponService.exchangeSdk(sdk);
        return Result.success(mgs);
    }

}
